package StuManagerSystem.service;

import java.util.List;
import java.util.Scanner;

import StuManagerSystem.bean.Person;
import StuManagerSystem.bean.Student;
import StuManagerSystem.bean.Teacher;

public class AdminService {
	
	public static boolean addStudent(List<Person> studentList) {
		Scanner sc = new Scanner(System.in);
		System.out.println("\t\t添加学生信息");
		System.out.print("\t\t学号：");
		String number = sc.next();
		System.out.print("\t\t姓名：");
		String username = sc.next();
		String password = "123456";
		System.out.print("\t\t性别：");
		String sex = sc.next();
		System.out.print("\t\t年龄：");
		Integer age = sc.nextInt();
		System.out.print("\t\t专业：");
		String major = sc.next();
		Student stu = new Student(number, username, password, sex, age, 1, major, 0, 0, 0);
		if(studentList.add(stu)) {
			return true;
		}else {
			return false;
		}
	}
	
	public static void checkAllStudent(List<Person> studentList) {
		System.out.println("\t\t查看学生信息");
		System.out.println("\t\t学号\t\t|\t姓名\t|\t性别\t|\t年龄\t|\t专业\t\t|\t语文\t|\t数学\t|\t英语");
		for (Person s : studentList) {
			Student student = (Student)s;
			System.out.println("\t\t"+student.getNumber()+"\t|\t"+student.getUsername()+"\t|\t"+student.getSex()+"\t|\t"+
			student.getAge()+"\t|\t"+student.getMajor()+"\t|\t"+student.getChinese()+"\t|\t"+
					student.getMath()+"\t|\t"+student.getEnglish());
		}
	}
	
	public static boolean updateStudent(List<Person> studentList) {
		Scanner sc = new Scanner(System.in);
		System.out.println("\t\t修改学生信息");
		System.out.print("\t\t学号：");
		String number = sc.next();
		System.out.print("\t\t姓名：");
		String username = sc.next();
		System.out.print("\t\t密码：");
		String password = sc.next();
		System.out.print("\t\t性别：");
		String sex = sc.next();
		System.out.print("\t\t年龄：");
		Integer age = sc.nextInt();
		System.out.print("\t\t专业：");
		String major = sc.next();
		for(int i=0;i<studentList.size();i++) {
			if(number.equals(studentList.get(i).getNumber())) {
				studentList.get(i).setUsername(username);
				studentList.get(i).setPassword(password);
				studentList.get(i).setSex(sex);
				studentList.get(i).setAge(age);
				((Student)studentList.get(i)).setMajor(major);
				return true;
				
			}
		}
		return false;
	}
	
	public static boolean deleteStudent(List<Person> studentList) {
		Scanner sc = new Scanner(System.in);
		System.out.println("\t\t删除学生信息");
		System.out.print("\t\t请输入要删除的学生信息的学号：");
		String numberDel = sc.next();
		for(int i=0; i<studentList.size();i++) {
			if(numberDel.equals(studentList.get(i).getNumber())) {
				studentList.remove(i);
				return true;
			}
		}
		return false;
	}
	
	public static boolean addTeacher(List<Person> teacherList) {
		Scanner sc = new Scanner(System.in);
		System.out.println("\t\t添加教师信息");
		System.out.print("\t\t工号：");
		String number = sc.next();
		System.out.print("\t\t姓名：");
		String username = sc.next();
		String password = "123456";
		System.out.print("\t\t性别：");
		String sex = sc.next();
		System.out.print("\t\t年龄：");
		Integer age = sc.nextInt();
		System.out.print("\t\t课程：");
		String course = sc.next();
		Teacher teacher = new Teacher(number, username, password, sex, age, 2, course);
		if(teacherList.add(teacher)) {
			return true;
		}else {
			return false;
		}
	}
	
	public static void checkAllTeacher(List<Person> teacherList) {
		System.out.println("\t\t查看教师信息");
		System.out.println("\t\t工号\t|\t姓名\t|\t性别\t|\t年龄\t|\t课程");
		for (Person t : teacherList) {
			Teacher teacher = (Teacher)t;
			System.out.println("\t\t"+teacher.getNumber()+"\t|\t"+teacher.getUsername()+"\t|\t"+teacher.getSex()+"\t|\t"+
					teacher.getAge()+"\t|\t"+teacher.getCourse());
		}
	}
	
	public static boolean updateTeacher(List<Person> teacherList) {
		Scanner sc = new Scanner(System.in);
		System.out.println("\t\t修改教师信息");
		System.out.print("\t\t学号：");
		String numberT = sc.next();
		System.out.print("\t\t姓名：");
		String usernameT = sc.next();
		System.out.print("\t\t密码：");
		String passwordT = sc.next();
		System.out.print("\t\t性别：");
		String sexT = sc.next();
		System.out.print("\t\t年龄：");
		Integer ageT = sc.nextInt();
		System.out.print("\t\t课程：");
		String courseT = sc.next();
		for(int i=0;i<teacherList.size();i++) {
			if(numberT.equals(teacherList.get(i).getNumber())) {
				teacherList.get(i).setUsername(usernameT);
				teacherList.get(i).setPassword(passwordT);
				teacherList.get(i).setSex(sexT);
				teacherList.get(i).setAge(ageT);
				((Teacher)teacherList.get(i)).setCourse(courseT);
				return true;
			}
		}
		return false;
	}

	public static boolean deleteTeacher(List<Person> teacherList) {
		Scanner sc = new Scanner(System.in);
		System.out.println("\t\t删除教师信息");
		System.out.print("\t\t请输入要删除的教师信息的工号：");
		String number = sc.next();
		for(int i=0; i<teacherList.size();i++) {
			if(number.equals(teacherList.get(i).getNumber())) {
				teacherList.remove(i);
				return true;
			}
		}
		return false;
	}
}
